//package com.ophiux.utils.aspect;
//
//import java.lang.reflect.Method;
//import java.util.concurrent.TimeUnit;
//
//import javax.servlet.http.HttpServletRequest;
//
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Pointcut;
//import org.aspectj.lang.reflect.MethodSignature;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.core.StringRedisTemplate;
//import org.springframework.stereotype.Component;
//
//import com.alibaba.fastjson.JSON;
//import com.esiran.admin.util.RequestHolder;
//import com.esiran.common.annotation.NoRepeatSubmit;
//import com.esiran.common.entity.APIException;
//import com.esiran.common.util.IPUtil;
//import com.esiran.common.util.MD5Utils;
//import com.esiran.common.util.RequestHolderUtil;
//
//import lombok.extern.slf4j.Slf4j;
//
///**
// * @desc：接口防重复切面<br>
// * @author: hhl<br>
// * @date: 2021年9月2日 下午4:57:56<br>
// */
//@Aspect
//@Component
//@Slf4j
//public class NoRepeatSubmitAop {
//
//    @Pointcut("@annotation(com.esiran.common.annotation.NoRepeatSubmit)")
//    public void serviceNoRepeat() {
//    }
//    
//    @Autowired
//    StringRedisTemplate stringRedisTemplate;
//
//    @Around("serviceNoRepeat()")
//    public Object around(ProceedingJoinPoint point) throws Throwable {
//
//        HttpServletRequest request = RequestHolder.getRequest();
//        String jwtToken = RequestHolderUtil.getRequestToken(request);
//        String ip = IPUtil.getIpAddress(request);
//        
//        //获取注解
//        MethodSignature signature = (MethodSignature) point.getSignature();
//        Method method = signature.getMethod();
//        //目标类、方法
//        String className = method.getDeclaringClass().getName();
//        String name = method.getName();
//        String key = String.format("%s_%s_%s.%s_%s",jwtToken, ip,className,name,JSON.toJSONString(request.getParameterMap()));
//        key = MD5Utils.md5Password(key);
//        log.info(JSON.toJSONString(request.getParameterMap()));
//        if (stringRedisTemplate.opsForValue().get(key) == null) {
//            try {
//                Object o = point.proceed();
//                NoRepeatSubmit noRepeatSubmit = signature.getMethod().getAnnotation(NoRepeatSubmit.class);
//                // 默认1秒内统一用户同一个地址同一个参数，视为重复提交
//                stringRedisTemplate.opsForValue().set(key, "0",noRepeatSubmit.time(),TimeUnit.SECONDS);
//                return o;
//            }catch (Exception e){
//                throw new Exception(e.getMessage(),e.getCause());
//            }
//        } else {
//            throw new APIException("重复提交","ERROR");
//        }
//    }
//
//}